package com.rr.config.ai;

import com.rr.advisors.MyLoggerAdvisor;
import com.rr.tools.SystemTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatClientConfig {


    @Bean
    public ChatClient serviceChatClient(
            @Qualifier("openAiChatModel") ChatModel model,
            @Qualifier("springChatMemory") ChatMemory springChatMemory,
            SystemTools systemTools){

        return  ChatClient.builder(model).
            defaultAdvisors(new MyLoggerAdvisor(), MessageChatMemoryAdvisor.builder(springChatMemory).build())
                .defaultTools(systemTools)
                .build();
        }
    @Bean
    public ChatMemory springChatMemory(){
        return MessageWindowChatMemory.builder().maxMessages( 10).build();
    }
}
